extends CanvasLayer

@onready var itemPanel = $ItemPanel
@onready var playerSelectPanel = $PlayerSelectPanel
@onready var itemTypePanel = $ItemTypePanel
@onready var entityBoundItemPanel = $EntityBoundItemPanel
@onready var infoDialog = $InfoDialog
@onready var propertyPanel = $PropertyPanel

@export var enableInput = true

var currentItemTypeTab = ""
var currentSelectedEntityData = null
var itemPopup = null


func _ready():
	hide()
	

func showAll():
	playerSelectPanel.init()
	itemTypePanel.init()
	itemPanel.initItems()
	entityBoundItemPanel.initItems()
	propertyPanel.init()
	
	checkAndRecoverSelect()
	
	show()


func onSelectItemType(sender, config):	
	itemPanel.initItems()
	

func onSelectEntity(sender, data):
	currentSelectedEntityData = data
	entityBoundItemPanel.initItems()
	propertyPanel.init()
	
	
func checkAndRecoverSelect():
	if currentItemTypeTab != "":
		itemTypePanel.select(currentItemTypeTab)
	else:
		itemTypePanel.selectFirst()
		
	if currentSelectedEntityData:
		playerSelectPanel.select(currentSelectedEntityData)
	else:
		playerSelectPanel.selectFirst()
	
	
func reOpen():
	hideAll()
	showAll()
	

func hideAll():
	hide()
	
	if itemPopup: 
		itemPopup.queue_free()
		itemPopup = null
	

	
